package org.example.JVM.ByteCode.Handler;

import org.example.JVM.ByteCode.Type.ClassFile;
import org.example.JVM.ByteCode.Type.U2;

import java.nio.ByteBuffer;

/**
 * @description:根据this_class的值到常量池取得对应的Class_info常量，
 *              再从Class_info常量中获取该常量的name_index的值，
 *              最后根据name_index回到常量池中取得对应的Utf8_info常量，这样就可以取得具体的类名了
 * @author: farprt
 * @create: 2022-11-13 16:57
 **/
public class ThisAndSuperClassHandler implements BaseByteCodeHandler {
    @Override
    public int order() {
        return 4;
    }

    @Override
    public void read(ByteBuffer codeBuf, ClassFile classFile) throws Exception {
        classFile.setThis_class(new U2(codeBuf.get(), codeBuf.get()));
        classFile.setSuper_class(new U2(codeBuf.get(), codeBuf.get()));
    }
}